const axios = require('axios');

// 测试技师API
async function testTechnicianAPI() {
    try {
        console.log('测试技师API...');

        // 测试获取技师列表
        const response = await axios.get('http://localhost:4002/api/quick-registration/technicians');

        console.log('API响应状态:', response.status);
        console.log('API响应数据:', JSON.stringify(response.data, null, 2));

        if (response.data.code === 200) {
            console.log('✅ 技师API测试成功！');
            console.log(`找到 ${response.data.data.length} 个技师`);

            response.data.data.forEach((tech, index) => {
                console.log(`${index + 1}. ${tech.name} - 评分: ${tech.rating} - 技能: ${tech.skills.join(', ')}`);
            });
        } else {
            console.log('❌ 技师API测试失败:', response.data.message);
        }

    } catch (error) {
        console.error('❌ API测试失败:', error.message);
        if (error.response) {
            console.error('响应状态:', error.response.status);
            console.error('响应数据:', error.response.data);
        }
    }
}

// 测试服务API
async function testServiceAPI() {
    try {
        console.log('\n测试服务API...');

        const response = await axios.get('http://localhost:4002/api/quick-registration/services');

        console.log('API响应状态:', response.status);

        if (response.data.code === 200) {
            console.log('✅ 服务API测试成功！');
            console.log(`找到 ${response.data.data.length} 个服务项目`);

            response.data.data.forEach((service, index) => {
                console.log(`${index + 1}. ${service.name} - ¥${service.price} - ${service.duration}分钟`);
            });
        } else {
            console.log('❌ 服务API测试失败:', response.data.message);
        }

    } catch (error) {
        console.error('❌ 服务API测试失败:', error.message);
    }
}

// 运行测试
async function runTests() {
    console.log('开始API测试...\n');

    await testServiceAPI();
    await testTechnicianAPI();

    console.log('\nAPI测试完成！');
}

// 如果直接运行此文件，则执行测试
if (require.main === module) {
    runTests();
}

module.exports = { testTechnicianAPI, testServiceAPI }; 